#include <regx52.h>
#include "oled.h"
#include "HC_SR04.h"

unsigned int number = 0;
int main(){
    unsigned int int_cm,decimal_cm;
	OLED_Init();
	HC_SR04_Init();
    OLED_ShowString(1,1,"Distance:");
	while(1){
        int_cm = (unsigned int)(HC_SR04_Value * 1.7f/100.0f);
        decimal_cm = (unsigned int)(HC_SR04_Value * 170 % 100);

        if(int_cm > 200)
            OLED_ShowString(3,1,"Out of range");
        else
            OLED_ShowString(3,1,"            ");
            OLED_ShowNum(2,1,int_cm, 4);
            OLED_ShowChar(2,5,'.');
            OLED_ShowNum(2,6,decimal_cm, 2);
            OLED_ShowString(2,8,"cm");
	}
}